package net.oschina.app.viewpagerfragment.MyFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import net.oschina.app.R;
import net.oschina.app.util.UIUtils;

/**
 * Created by foty on 2017/4/2.
 * ?
 * fragmentde只有一个recyclerview（Xrecyclerview）的fragment的基类,
 */

public abstract class BaseItemFragment extends Fragment {

    public FrameLayout mViewCont;

    public BaseItemFragment() {
        mViewCont = (FrameLayout) View.inflate(UIUtils.getContext(),R.layout.item_fragment_container,null);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return mViewCont;
    }

    public abstract void showItemFragmentView() ;
    public abstract void loadDates();

    //更换tab与fragment的视图
    public void changeView(View view){
        mViewCont.removeAllViews();
        mViewCont.addView(view);
    }


    //当这个fragment可以看到时，加载数据，此方法优先于 oncreateview（）,用此方法可以防止数据加载过多,优化内存
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser){
            //加载数据..
            showItemFragmentView();
            loadDates();
        }
    }
}
